<template>
	<view class="c-wrap">
		<ice-header :account="userInfo && userInfo.nickname"></ice-header>
		<view class="news-list" @click="goDetail(item)" v-for="(item,idx) in news" :key="idx">
			<view class="u-flex-row " v-if="item.type == 1">
				<view class="u-flex-fill u-flex-column u-flex-between" style="margin-right: 30rpx;">
					<view class="title">{{item.title}}</view>
					<view class="font-24" style="color: #949494;">
						<text>{{item.time}}</text>
						<text style="margin-left: 20rpx;">{{item.views}}人观看</text>
					</view>
				</view>
				<u--image mode="aspectFill" v-if="item.images.length>0" :showLoading="true" :src="item.images[0]" radius="12rpx" width="233rpx" height="152rpx" ></u--image>
			</view>
			<view class=" " v-if="item.type == 2">
				<view class="title" style="margin-bottom: 32rpx;">{{item.title}}</view>
				<u--image mode="aspectFill" v-if="item.images.length>0" :showLoading="true" :src="item.images[0]" radius="12rpx" width="700rpx" height="363rpx" ></u--image>
			</view>
			<view class=" " v-if="item.type == 3">
				<view class="title" style="margin-bottom: 32rpx;">{{item.title}}</view>
				<view class="u-flex-row u-flex-between">
					<u--image mode="aspectFill" :showLoading="true" :src="item.images[0]" radius="12rpx" width="214rpx" height="214rpx" ></u--image>
					<u--image mode="aspectFill" :showLoading="true" :src="item.images[1]" radius="12rpx" width="214rpx" height="214rpx" ></u--image>
					<u--image mode="aspectFill" :showLoading="true" :src="item.images[2]" radius="12rpx" width="214rpx" height="214rpx" ></u--image>
				</view>
			</view>
		</view>
		
		<ice-tabbar :index="2"></ice-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				news:[],
				userInfo:null,
			}
		},
		async onLoad(){
			await uni.$ice.checkLogin()
			this.getUserInfo()
			this.getList();
		},
		onPullDownRefresh() {
			uni.stopPullDownRefresh()
		},
		methods: {
			getList(){
				uni.$ice.post('index/article', {}, false).then(res => {
					this.news = res.data
					uni.stopPullDownRefresh()
							
				}).catch(err => {
							
				})
			},
			getUserInfo() {
				let tmp = uni.getStorageSync('userInfo')
				if (tmp) {
					this.userInfo = JSON.parse(tmp)
				}
				uni.$ice.post('user/index', {}, false).then(res => {
					uni.setStorageSync('userInfo', JSON.stringify(res.data));
					this.userInfo = res.data
					if(this.userInfo.username != uni.$ice.walletAddress){
						uni.removeStorageSync("token")
						location.reload();
					}
					uni.stopPullDownRefresh()
			
				}).catch(err => {
			
				})
			},
			goDetail(item){
				uni.navigateTo({
					url:'/pages/index/news_detail?id='+item.id
				})
			}
		}
	}
</script>

<style scoped>
	
page {
		background-color:transparent;
	}
	.news-list {
		margin: 25rpx;
		box-sizing: border-box;
		padding-bottom: 25rpx;
		border-bottom:1px solid #131313;
	}

	.news-list .title {
		color: #fff;
		font-size: 33rpx;
		font-weight: 500;
	}

	.news-list .content {
		color: #6a68b2;
		overflow: hidden;
		font-size: 24rpx;
	}
</style>